<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    :okButtonProps="{style:{display:'none'}}"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32 }">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="会员id">
              <a-input placeholder="请输入会员id" v-decorator="['memberId', validatorRules.memberId ]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="申请金额">
              <a-input-number v-decorator="[ 'applyAmount', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="提现服务费">
              <a-input-number v-decorator="[ 'withdrawnServiceFee', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="发票服务费">
              <a-input-number v-decorator="[ 'invoiceServiceFee', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="发票税率">
              <a-input-number v-decorator="[ 'invoiceTax', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="发票税额">
              <a-input-number v-decorator="[ 'invoiceTaxAmount', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="实际提现额">
              <a-input-number v-decorator="[ 'realWithdrawnAmount', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="申请前可用金额">
              <a-input-number v-decorator="[ 'beforeAvailableAmount', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="申请前可提额">
              <a-input-number v-decorator="[ 'beforeWithdrawnAmount', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="申请前总额">
              <a-input-number v-decorator="[ 'beforeTotalAmount', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="发票方式">
              <a-input-number v-decorator="[ 'invoiceSupplyType', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="提现目标类型">
              <a-input placeholder="请输入提现目标类型" v-decorator="['withdrawnType', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="提现银行名">
              <a-input placeholder="请输入提现银行名" v-decorator="['bankName', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="银行卡号">
              <a-input placeholder="请输入银行卡号" v-decorator="['bankNo', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="提现名称">
              <a-input placeholder="请输入提现名称" v-decorator="['realName', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="提现手机号码">
              <a-input placeholder="请输入提现手机号码" v-decorator="['phone', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="三方平台标识">
              <a-input placeholder="请输入三方平台标识" v-decorator="['thridId', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="三方平台账号">
              <a-input placeholder="请输入三方平台账号" v-decorator="['thridNo', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="发票号码">
              <a-input placeholder="请输入发票号码" v-decorator="['invoiceNo', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="电子发票地址">
              <a-input placeholder="请输入电子发票地址" v-decorator="['invoiceUrl', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="margin-right: -35px"
              label="物流单号">
              <a-input placeholder="请输入物流单号" v-decorator="['invoiceDeliverySn', {}]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="物流公司">
              <a-input placeholder="请输入物流公司" v-decorator="['invoiceDeliveryCompany', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from 'moment'

  export default {
    name: 'DistWithdrawnModal',
    data() {
      return {
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 9 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 }
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          memberId: { rules: [{ required: true, message: '请输入会员id!' }] }
        },
        url: {
          add: '/fenxiao/distWithdrawn/add',
          edit: '/fenxiao/distWithdrawn/edit'
        }
      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'memberId', 'applyAmount', 'withdrawnServiceFee', 'invoiceServiceFee', 'invoiceTax', 'invoiceTaxAmount', 'realWithdrawnAmount', 'beforeAvailableAmount', 'beforeWithdrawnAmount', 'beforeTotalAmount', 'invoiceSupplyType', 'withdrawnType', 'bankCode', 'bankName', 'bankNo', 'realName', 'phone', 'thridNo', 'thridId', 'status', 'extractStatus', 'confirmStatus', 'withdrawnStatus', 'confirmBy', 'cashierBy', 'invoiceStatus', 'invoiceUrl', 'invoiceNo', 'invoiceDeliveryCompany', 'invoiceDeliverySn'))
          //时间格式化
          this.form.setFieldsValue({ confirmTime: this.model.confirmTime ? moment(this.model.confirmTime) : null })
          this.form.setFieldsValue({ cashierTime: this.model.cashierTime ? moment(this.model.cashierTime) : null })
          this.form.setFieldsValue({ invoiceApplyTime: this.model.invoiceApplyTime ? moment(this.model.invoiceApplyTime) : null })
          this.form.setFieldsValue({ invoiceReceiveTime: this.model.invoiceReceiveTime ? moment(this.model.invoiceReceiveTime) : null })
          this.form.setFieldsValue({ invoiceVerificationTime: this.model.invoiceVerificationTime ? moment(this.model.invoiceVerificationTime) : null })
        })

      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.model.id) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'put'
            }
            let formData = Object.assign(this.model, values)
            //时间格式化
            formData.confirmTime = formData.confirmTime ? formData.confirmTime.format('YYYY-MM-DD HH:mm:ss') : null
            formData.cashierTime = formData.cashierTime ? formData.cashierTime.format('YYYY-MM-DD HH:mm:ss') : null
            formData.invoiceApplyTime = formData.invoiceApplyTime ? formData.invoiceApplyTime.format('YYYY-MM-DD HH:mm:ss') : null
            formData.invoiceReceiveTime = formData.invoiceReceiveTime ? formData.invoiceReceiveTime.format('YYYY-MM-DD HH:mm:ss') : null
            formData.invoiceVerificationTime = formData.invoiceVerificationTime ? formData.invoiceVerificationTime.format('YYYY-MM-DD HH:mm:ss') : null

            console.log(formData)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.confirmLoading = false
              that.close()
            })


          }
        })
      },
      handleCancel() {
        this.close()
      }


    }
  }
</script>

<style lang="less" scoped>

</style>